/*
 * jQuery button 0.1
 * http://www.bsweb.com.cn
 * 需要库文件
 * 		jquery-ui.js
 */
(function($,undefined){
	$.widget("ui.button",{
		options:{
			id:null,
			disabled:false,
			plain:false,
			text:'',
			iconCls:null,
			handler:null
		},
		_create:function(){
			var text = "";
			if(this.options.text == ""){
				this.options.text = this.element.html();
			}			
			var buttonCtx = $("<span class='bs-button-left'><span class='bs-button-text'></span></span>");			
			this.element.html("").append(buttonCtx).addClass("bs-button");
			this.element.find(".bs-button-text").html(this.options.text);
		},
		_init:function(){
			var _self = this;			
			if(this.options.id != null){
				this.element.attr("id",this.options.id);
			}		
		
			if(this.options.plain == true){
				this.element.addClass("bs-button-plain").css("height","22px");
			}
			this.element.hover(function(){						
				if(_self.options.plain != true){
					$(this).addClass("bs-button-hover");
					$(this).find(".bs-button-left").addClass("bs-button-left-hover");
				}
			},function(){
				if(_self.options.plain != true){
					$(this).removeClass("bs-button-hover");
					$(this).find(".bs-button-left").removeClass("bs-button-left-hover");
				}
			})
			if(this.options.iconCls != null){				
				this.element.find(".bs-button-text").addClass(this.options.iconCls);
				if (this.options.text == "") {
					this.element.find(".bs-button-text").css("padding-left", "16px");
				}else{
					this.element.find(".bs-button-text").css("padding-left", "20px");
				}
			}
			
			if($.isFunction(_self.options.handler)){				
				this.element.click(_self.options.handler);
			}
			
			if(this.options.disabled == true){
				this.element.unbind("click");
				this.element.addClass("bs-button-disable");
			}
		},
		disable:function(){
			var _self = this;
			this.options.disabled = true;			
			this.element.addClass("bs-button-disable");
			this.element.unbind("click");
		},
		enable:function(){
			var _self = this;
			this.options.disabled = false;
			this.element.unbind("click");
			if($.isFunction(this.options.handler)){
				_self.element.click(_self.options.handler);
			}			
			this.element.removeClass("bs-button-disable");
		}
	})
})(jQuery)
